package com.common.enumbean;



import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum Gender {
    MALE("男"),
    FEMALE("女");
    @EnumValue
    private final String name;

    Gender(String name) {
        this.name = name;
    }

    // 序列化时使用 name 属性
    @JsonValue
    public String getName() {
        return name;
    }

    // 反序列化时根据 name 查找枚举
    @JsonCreator
    public static Gender fromName(String name) {
        for (Gender gender : Gender.values()) {
            if (gender.name.equals(name)) {
                return gender;
            }
        }
        throw new IllegalArgumentException("无效的性别: " + name);
    }
}
